package com.max.rabbitmq.learn.simple;

import com.max.rabbitmq.learn.util.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * @description 简单模式接收者
 * @author yandong
 * @create 2021年4月06日 12:15:50
 */
public class Recv {
    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = ConnectionUtil.getConnection();
        //获取chanel chanel是操作rabbitmq broker的接口，即操作amqp协议的对象
        Channel channel = connection.createChannel();
        channel.queueDeclare("max-host-simple-mode", true, false, false, null);
        channel.basicConsume("max-host-simple-mode", false, ((consumerTag, message) -> {
            System.out.println("/****************************/");
            System.out.println("recv from exchange =" + message.getEnvelope().getExchange());
            System.out.println("routeKey = " + message.getEnvelope().getRoutingKey());
            System.out.println("messageId = " + message.getProperties().getMessageId());
            System.out.println("message = " + new String(message.getBody(), "UTF-8"));
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
        }), (consumerTag -> {

        }));

    }
}
